package com.baihan.angus.app.game.common.data_center.remote;

import com.baihan.angus.app.game.basic.base.BaseResponse;
import com.baihan.angus.app.game.basic.utils.net.ApiObserver;
import com.baihan.angus.app.game.basic.utils.net.RetrofitHelper;
import com.baihan.angus.app.game.common.bean.response.AlbumResponse;
import com.baihan.angus.app.game.common.bean.response.BbsResponse;
import com.baihan.angus.app.game.common.bean.response.CreatePhotoResponse;
import com.baihan.angus.app.game.common.bean.response.CreateRoomResponse;
import com.baihan.angus.app.game.common.bean.response.FeedbackResponse;
import com.baihan.angus.app.game.common.bean.response.LoginResponse;
import com.baihan.angus.app.game.common.bean.response.RankingResponse;
import com.baihan.angus.app.game.common.bean.response.RoomDetailResponse;
import com.baihan.angus.app.game.common.bean.response.RoomResponse;
import com.baihan.angus.app.game.common.bean.response.ScriptRankResponse;
import com.baihan.angus.app.game.common.bean.response.ScriptResponse;
import com.baihan.angus.app.game.common.bean.response.SmsCodeResponse;
import com.baihan.angus.app.game.common.bean.response.StoreResponse;
import com.baihan.angus.app.game.common.bean.response.UpgradeResponse;
import com.baihan.angus.app.game.common.bean.response.UploadMultipleResponse;
import com.baihan.angus.app.game.common.bean.response.UploadResponse;
import com.baihan.angus.app.game.common.bean.response.VerifyDetailResponse;
import com.baihan.angus.app.game.common.bean.response.VerifyStatusResponse;
import com.baihan.angus.app.game.common.data_center.remote.api.BbsServer;
import com.baihan.angus.app.game.common.data_center.remote.api.RoomServer;
import com.baihan.angus.app.game.common.data_center.remote.api.ScriptServer;
import com.baihan.angus.app.game.common.data_center.remote.api.StoreServer;
import com.baihan.angus.app.game.common.data_center.remote.api.UploadServer;
import com.baihan.angus.app.game.common.data_center.remote.api.UserServer;
import com.trello.rxlifecycle2.LifecycleTransformer;

import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MultipartBody;

public class RemoteDataMng {
    private static RemoteDataMng mRemoteDataMng;

    private RemoteDataMng() {
    }

    public static synchronized RemoteDataMng getInstance() {
        if (mRemoteDataMng == null) mRemoteDataMng = new RemoteDataMng();
        return mRemoteDataMng;
    }

    public void getSmsCode(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<SmsCodeResponse> observer) {
        RetrofitHelper.createApi(UserServer.class).getCode(pMap).compose(transformer).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void codeLogin(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<LoginResponse> observer) {
        RetrofitHelper.createApi(UserServer.class).codeLogin(pMap).compose(transformer).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void getRoomList(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<RoomResponse> apiObserver) {
        RetrofitHelper.createApi(RoomServer.class).getRoomList(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void logout(LifecycleTransformer transformer, ApiObserver<BaseResponse> observer) {
        RetrofitHelper.createApi(UserServer.class).logout().compose(transformer).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void getScriptList(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<ScriptResponse> apiObserver) {
        RetrofitHelper.createApi(ScriptServer.class).getScriptList(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void createRoom(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<CreateRoomResponse> observer) {
        RetrofitHelper.createApi(RoomServer.class).createRoom(pMap).compose(transformer).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void getRoomDetail(String sn, LifecycleTransformer transformer, ApiObserver<RoomDetailResponse> observer) {
        RetrofitHelper.createApi(RoomServer.class).getRoomDetail(sn).compose(transformer).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void enterRoom(String sn, Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<BaseResponse> observer) {
        RetrofitHelper.createApi(RoomServer.class).enterRoom(sn, pMap).compose(transformer).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void exitRoom(String sn, Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<BaseResponse> observer) {
        RetrofitHelper.createApi(RoomServer.class).exitRoom(sn, pMap).compose(transformer).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void disbandRoom(String sn, LifecycleTransformer transformer, ApiObserver<BaseResponse> observer) {
        RetrofitHelper.createApi(RoomServer.class).dissolutionRoom(sn).compose(transformer).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void uploadFile(MultipartBody.Part file, LifecycleTransformer transformer, ApiObserver<UploadResponse> apiObserver) {
        RetrofitHelper.createApi(UploadServer.class).uploadFile(file).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void uploadFileList(List<MultipartBody.Part> files, LifecycleTransformer transformer, ApiObserver<UploadMultipleResponse> apiObserver) {
        RetrofitHelper.createApi(UploadServer.class).uploadFileList(files).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void modifyUserInfo(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<BaseResponse> apiObserver) {
        RetrofitHelper.createApi(UserServer.class).modifyUserInfo(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void feedback(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<FeedbackResponse> apiObserver) {
        RetrofitHelper.createApi(UserServer.class).feedback(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void upgrade(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<UpgradeResponse> apiObserver) {
        RetrofitHelper.createApi(UserServer.class).upgrade(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void getUserInfo(LifecycleTransformer transformer, ApiObserver<LoginResponse> observer) {
        RetrofitHelper.createApi(UserServer.class).getUserInfo().compose(transformer).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void getBbsList(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<BbsResponse> apiObserver) {
        RetrofitHelper.createApi(BbsServer.class).getBbsList(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void getAllScript(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<BaseResponse> apiObserver) {
        RetrofitHelper.createApi(ScriptServer.class).getAllScript(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void getScriptRankList(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<ScriptRankResponse> apiObserver) {
        RetrofitHelper.createApi(ScriptServer.class).getScriptRankList(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void getRankList(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<RankingResponse> apiObserver) {
        RetrofitHelper.createApi(ScriptServer.class).getScriptRankList(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void getVerifyDetail(String id, String user, LifecycleTransformer transformer, ApiObserver<VerifyDetailResponse> apiObserver) {
        RetrofitHelper.createApi(UserServer.class).getVerifyDetail(id, user).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void getVerifyStatus(String id, LifecycleTransformer transformer, ApiObserver<VerifyStatusResponse> apiObserver) {
        RetrofitHelper.createApi(UserServer.class).getVerifyStatus(id).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void updateUpgrade(String id, Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<UpgradeResponse> apiObserver) {
        RetrofitHelper.createApi(UserServer.class).updateUpgrade(id, pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void getStoreList(int role_id, Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<StoreResponse> apiObserver) {
        RetrofitHelper.createApi(StoreServer.class).getStoreList(role_id, pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void getPhotoList(LifecycleTransformer transformer, ApiObserver<AlbumResponse> apiObserver) {
        RetrofitHelper.createApi(UserServer.class).getPhotoList().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void createPhotoList(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver<CreatePhotoResponse> apiObserver) {
        RetrofitHelper.createApi(UserServer.class).createPhotoList(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

}
